package org.jeecg.modules.api.officebalancelog.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.api.member.entity.Member;
import org.jeecg.modules.api.officebalancelog.entity.OfficeBalanceLog;
import org.jeecg.modules.api.officebalancelog.mapper.OfficeBalanceLogMapper;
import org.jeecg.modules.api.officebalancelog.service.IOfficeBalanceLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 商户余额历史 蓝客帝数据库
 * @author: Young Jun
 * @date: 2024年09月27日 16:02
 */
@Service
@DS("lkd")
public class OfficeBalanceLogServiceImpl extends ServiceImpl<OfficeBalanceLogMapper, OfficeBalanceLog> implements IOfficeBalanceLogService {

    @Autowired
    private OfficeBalanceLogMapper officeBalanceLogMapper;
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public String getSourceUserIdByLkdOrderId(String orderId) {
        String sqlStr = "SELECT user_id FROM t_order WHERE id = \"{}\"";
        String formatSql = StrUtil.format(sqlStr, orderId);
        return jdbcTemplate.queryForObject(formatSql, String.class);
    }

    @Override
    public int validCount(List<String> userIds, String startTime, String endTime) {
        List<String> ids = new ArrayList<>();
        if (userIds.size() == 0) {
            return 0;
        }
        for (String id : userIds) {
            ids.add("'" + id + "'");
        }
        return officeBalanceLogMapper.validCount(String.join(",", ids), startTime, endTime);
    }

    @Override
    public List<String> getFxOrderList() {
        return officeBalanceLogMapper.getFxOrderList();
    }

    @Override
    public int updateOrderStatus(String id, int preState, int state) {
        return officeBalanceLogMapper.updateOrderStatus(id,preState,state);
    }
}
